/**
 * 
 */
package com.patternity.model;

import java.util.ArrayList;
import java.util.List;

/**
 * Represents an association (e.g. inheritance, delegation or instantiation)
 * between two elements
 * 
 * @author Cyrille.Martraire
 */
// @ValueObject
public class Relation {

	private final String name;

	private final Object from;

	private final Object to;

	public static final String DELEGATION = "Delegation";

	public static final String GENERALISATION = "Generalisation";

	public static final String INSTANTIATION = "Instantiation";

	private final List<String> stereotypes = new ArrayList<String>();

	public Relation(final String name, final Object from, final Object to) {
		this.name = name;
		this.from = from;
		this.to = to;
	}

	public String getName() {
		return name;
	}

	public Object getFrom() {
		return from;
	}

	public Object getTo() {
		return to;
	}

	public List<String> getStereotypes() {
		return stereotypes;
	}

	// Fluent interface
	public Relation addStereotype(final String stereotype) {
		stereotypes.add(stereotype);
		return this;
	}

	@Override
	public int hashCode() {
		return toString().hashCode();
	}

	@Override
	public boolean equals(final Object obj) {
		return toString().equals(obj.toString());
	}

	@Override
	public String toString() {
		return name + " from: " + from + " to: " + to + " " + stereotypes;
	}
}
